//
//  Deck.m
//  hanafudaIPhone
//
//  Created by 우성 김 on 12. 3. 26..
//  Copyright (c) 2012년 yy01ar@gmail.com. All rights reserved.
//

#import "Deck.h"
#import "Card.h"
#import "NSMutableArray+Shuffle.h"

@implementation Deck

@synthesize cardArray;

+(Deck*)createInitialDeck
{
//    NSMutableArray* initArray = [[NSMutableArray alloc]initWithCapacity:48];
//    for(int i = 1 ; i <= 12 ; i++)
    
//    NSMutableArray* initArray = [[NSMutableArray alloc]initWithCapacity:40];
    Deck* deck = [[Deck alloc]init];
    deck.cardArray = [[NSMutableArray alloc]initWithCapacity:40];

    for(int i = 1 ; i <= 10 ; i++)
        for(int j = 1 ; j <= 4 ; j++)
        {
            Card* card = [[Card alloc]initWithValue:i AndType:j];
            card.position = ccp(0, 0);
            [deck.cardArray addObject:card];
        }
    
    [deck.cardArray shuffle];
//    Deck* deck = [[Deck alloc]init];
//    deck.cardArray = initArray;
    return [deck autorelease];
}

+(Deck*)createEmptyDeck
{
    Deck* deck = [[Deck alloc]init];
    deck.cardArray = [[NSMutableArray alloc] init];
    return [deck autorelease];
}

-(void)add:(Card*) card
{
    [cardArray addObject:card];
}
-(void)addCardList:(NSMutableArray *)cardList
{
    [cardArray addObjectsFromArray:cardList];
}

-(BOOL)canPut
{
    return cardArray.count > 0;
}

-(Card*)put
{
    Card* card = [cardArray objectAtIndex:0];
    [cardArray removeObject:card];
    return card;
}

-(void)dealloc
{
    for(Card* card in cardArray)
    {
        [card release];
    }
    [cardArray release];
    [super dealloc];
}
@end
